package promotion

import (
	sqlc "bp/db/sqlc"
	"bp/internal/render"
	// sharedConv "bp/internal/rpcserver/shared/conv"
	sharedVld "bp/internal/rpcserver/shared/vld"
	"bp/internal/service/entity/promotion"
	"bp/internal/util"
	promotionGrpc "bp/rpc/gen/webapi/promotion"
	"context"
)


// VldGetPromotionReq 验证获取促销活动请求
func (s *PromotionWebApiImp) VldGetPromotionReq(ctx context.Context, q *sqlc.Queries, req *promotionGrpc.GetPromotionReq) (promotionID int64, err error) {
	slog := util.NewContextLogger(ctx, s.slog)
	if req.Id < 0 {
		err = render.InvalidArgumentRange("id")
		return
	}
	promotionID = req.Id
	slog.Infof("promotion_imp/query_vld.VldGetPromotionReq ok")
	return
}

// VldListPromotionsReq 验证列出促销活动请求
func (s *PromotionWebApiImp) VldListPromotionsReq(ctx context.Context, q *sqlc.Queries, req *promotionGrpc.ListPromotionsReq) (ptr *promotion.ListPromotionPtrsParam, err error) {
	slog := util.NewContextLogger(ctx, s.slog)

	if !sharedVld.IsPromotionStatusArray(req.PromotionStatuses, true) {
		err = render.InvalidArgumentValue("promotion_statuses")
		return
	}
	if !sharedVld.IsOfferTypeArray(req.OfferTypes, true) {
		err = render.InvalidArgumentValue("offer_types")
		return
	}
	ptr = &promotion.ListPromotionPtrsParam{
		PromotionStatuses: req.PromotionStatuses,
		OfferTypes:     req.OfferTypes,
		Keyword:        req.Keyword,
	}
	slog.Infof("promotion_imp/query_vld.VldGetPromotionReq ok")
	return
}

// VldListPromotionsReq 验证列出促销活动及其统计请求
func (s *PromotionWebApiImp) VldListPromotionWithStatsReq(ctx context.Context, q *sqlc.Queries, req *promotionGrpc.ListPromotionWithStatsReq) (ptr *promotion.ListPromotionWithStatPtrsParam, err error) {
	slog := util.NewContextLogger(ctx, s.slog)

	if !sharedVld.IsPromotionStatusArray(req.PromotionStatuses, true) {
		err = render.InvalidArgumentValue("promotion_statuses")
		return
	}
	if !sharedVld.IsOfferTypeArray(req.OfferTypes, true) {
		err = render.InvalidArgumentValue("offer_types")
		return
	}
	ptr = &promotion.ListPromotionWithStatPtrsParam{
		PromotionStatuses: req.PromotionStatuses,
		OfferTypes:     req.OfferTypes,
		Keyword:        req.Keyword,
	}
	slog.Infof("promotion_imp/query_vld.VldListPromotionWithStatsReq ok")
	return
}
